package com.apps.helper;

import com.apps.member.model.po.KupaMember;

import javax.servlet.http.HttpSession;

/**
 * 用户上下文
 * @author kingapex
 *
 */
public abstract class UserConextHelper {

	/**
	 * 用户端用
	 */
	public static final String CURRENT_MEMBER_KEY="curr_member";
	/**
	 * 管理后台用
	 */
	public static final String CURRENT_ADMIN_KEY="curr_admin";

	/**
	 * 获取当前登录的会员
	 * @return 如果没有登录返回null
	 */
	public static KupaMember getCurrentMember()
    {

		HttpSession sessonContext = ThreadContextHelper.getSession();
		if (sessonContext != null) {
			try {
                KupaMember member = (KupaMember) sessonContext.getAttribute(UserConextHelper.CURRENT_MEMBER_KEY);
				return member;
			} catch (IllegalStateException e) {
				return null;
			}
		}
		return null;
	}

	/**
	 * 从session中清除当前用户的登录信息
	 */
	public static void cleanCurrentMember()
	{
		ThreadContextHelper.getSession().removeAttribute(UserConextHelper.CURRENT_MEMBER_KEY);
	}


}
